//
//  DXHomeCell.swift
//  新浪微博
//
//  Created by dix on 2017/2/6.
//  Copyright © 2017年 dix. All rights reserved.
//

import UIKit

class DXHomeCell: UITableViewCell {
    //记录底部视图的顶部约束
    var bottomViewTopConstraint: Constraint?
    //提供属性供外界赋值
    var statusViewModel: DXStatusViewModel?{
        didSet{
           originalView.statusViewModel = statusViewModel
            //卸载约束
            bottomViewTopConstraint?.uninstall()
            //判断是否有转发微博
            if statusViewModel?.homeModel?.retweeted_status != nil {
                retweetView.statusViewModel = statusViewModel
                BottomView.snp_makeConstraints(closure: { (make) in
                   bottomViewTopConstraint = make.top.equalTo(retweetView.snp_bottom).constraint
                })
                retweetView.isHidden = false
            }else {
                BottomView.snp_makeConstraints(closure: { (make) in
                   bottomViewTopConstraint = make.top.equalTo(originalView.snp_bottom).constraint
                })
                retweetView.isHidden = true
            
            }
        }
    }

    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        setUpCellUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    //设置视图
    private func setUpCellUI(){
      //设置随机颜色
        backgroundColor = RGB(r: 235, g: 235, b: 235)
        //01 添加控件
        contentView.addSubview(originalView)
        contentView.addSubview(retweetView)
        contentView.addSubview(BottomView)
        //02 添加约束
        originalView.snp_makeConstraints { (make) in
            make.left.right.equalTo(contentView)
//            make.height.equalTo(50);
            make.top.equalTo(8)
        }
        retweetView.snp_makeConstraints { (make) in
//            make.height.equalTo(50)
            make.left.right.equalTo(contentView)
            make.top.equalTo(originalView.snp_bottom)
        }
        BottomView.snp_makeConstraints { (make) in
            make.left.right.equalTo(contentView)
            //记录约束
           bottomViewTopConstraint = make.top.equalTo(retweetView.snp_bottom).constraint
            make.height.equalTo(35)
            make.bottom.equalTo(contentView)
        }
    
    }
    private lazy var originalView: DXHomeOriginalView = DXHomeOriginalView()
    //转发微博
    private lazy var retweetView: DXHomeRetweetView = DXHomeRetweetView()
    private lazy var BottomView: DXHomeBtnView = DXHomeBtnView()
    
    
}
